package com.example.demo.entity;

import com.example.demo.enums.OrdersStatusEnum;
import lombok.Data;
import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单表
 */
@Entity
@Table(name = "orders")
@Data
public class Orders implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", insertable = false, nullable = false)
    private Long id;

    /**
     * 客户ID
     */
    @Column(name = "customer_id", nullable = false)
    private Long customerId;

    /**
     * 订单状态
     */
    @Column(name = "status", nullable = false)
    @Enumerated
    private OrdersStatusEnum status;

    /**
     * 创建时间
     */
    @Column(name = "create_date", nullable = false)
    private LocalDateTime createDate;

    /**
     * 订单编号
     */
    @Column(name = "sn", nullable = false)
    private String sn;

    /**
     * 订单金额
     */
    @Column(name = "amount")
    private BigDecimal amount = BigDecimal.ZERO;

    /**
     * 订单详情
     */
    @Transient
    private List<OrdersItem> itemList = new ArrayList<>();
}